package com.nut.controller;

import io.jsonwebtoken.Jwts;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.nio.charset.StandardCharsets;

/**
 * @ author : HyoJoo-W
 * @ createDate : 2021-05-10 20:08
 * @ Description : UserController
 */
@RestController
@RequestMapping("/user")
public class UserController
{
    /**
     * @Description UserController
     * @param authentication: 认证
     * @return java.lang.Object
     **/
    @RequestMapping("/getCurrentUser")
    public Object getCurrentUser(Authentication authentication, HttpServletRequest request)
    {
        //解析Jwt内容
        String header = request.getHeader("Authorization");
        String token = header.substring(header.indexOf("bearer") + 7);
        return Jwts.parser()
                .setSigningKey("test_key".getBytes(StandardCharsets.UTF_8))
                .parseClaimsJws(token)
                .getBody();
    }
}
